package problem;

/**
 * 死锁实例
 */
public class DeadLockDemo {
    public static void main(String[] args) {
        Object o1 = new Object();
        Object o2 = new Object();

        new Thread(() -> {
            synchronized (o1) {
                System.out.println("thread1 get o1");
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (o2) {
                    System.out.println("thread1 get o2");
                }
            }
        }).start();
        new Thread(() -> {
            synchronized (o2) {
                System.out.println("thread2 get o2");
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (o1) {
                    System.out.println("thread2 get o1");
                }
            }
        }).start();
    }
}
